//
//  NXSimplePopAlertViewLabel.m
//  GameBallMachine
//
//  Created by qqqwww on 2018/6/13.
//  Copyright © 2018年 qqqwww. All rights reserved.
//

#import "NXSimplePopAlertViewLabel.h"

#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height

#define kPadding 50  // Label距离屏幕左右的边距

@implementation NXSimplePopAlertViewLabel

+ (void)showshowPopAlertViewWithMessage:(NSString *)message withLabelViewAlpha:(CGFloat)alpha setInsertWidth:(int)insertWidth insertHeiht:(int)insertHeight andFrameCenterYoffset:(CGFloat)offset{
    
    NXSimplePopAlertViewLabel *tempLabel = [[NXSimplePopAlertViewLabel alloc] init];
    tempLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.f];

    [tempLabel showPopAlertViewWithMessage:message withLabelViewAlpha:alpha setInsertWidth:insertWidth insertHeiht:insertHeight andFrameCenterYoffset:offset];
}

- (void)showPopAlertViewWithMessage:(NSString *)message withLabelViewAlpha:(CGFloat)alpha setInsertWidth:(int)insertWidth insertHeiht:(int)insertHeight andFrameCenterYoffset:(CGFloat)offset{
    
    
    UIWindow *mainWindow = [UIApplication sharedApplication].keyWindow;
    
    /*
     UIButton *backgroundView = [[UIButton alloc] initWithFrame:[UIScreen mainScreen].bounds];
     
     [mainWindow addSubview:backgroundView];
     
     backgroundView.userInteractionEnabled = NO;
     */
    
    self.text = message;
    self.numberOfLines = 0;
    self.textAlignment = NSTextAlignmentCenter;
    self.backgroundColor = [UIColor blackColor];
    self.textColor = [UIColor whiteColor];
    self.alpha = 0;
    self.layer.cornerRadius = 8;
    self.layer.masksToBounds = YES;
    //  设置宽高限制
    CGSize sizesize = CGSizeMake(kScreenWidth - 2 * kPadding, MAXFLOAT);
    //  用文字计算出Size
    CGSize sizeTop = [self stringWithSizeLine:self.text font:self.font size:sizesize];
    //  设置frame
    self.frame = CGRectMake(0, 0, sizeTop.width + insertWidth, sizeTop.height + insertHeight);
    //    self.showLabel = showLabel;
    self.center = CGPointMake(kScreenWidth *0.5, kScreenHeight * offset);
    
    //  动画
    [UIView animateWithDuration:1.0f animations:^{
        self.alpha = alpha;
        [mainWindow addSubview:self];
    } completion:^(BOOL finished) {
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            [UIView animateWithDuration:1.0f animations:^{
                self.alpha = 0;
            } completion:^(BOOL finished) {
                [self removeFromSuperview];
            }];
        });
        
    }];
}

-(CGSize )stringWithSizeLine:(NSString *)str font:(UIFont *)font size:(CGSize)size
{
    NSMutableDictionary * Att= [NSMutableDictionary dictionary];
    Att[NSFontAttributeName] = font;
    return  [str boundingRectWithSize:size
                              options:NSStringDrawingUsesLineFragmentOrigin
                           attributes:Att context:nil].size;
}

+(void)alertError:(NSString *)error {
    
    [NXSimplePopAlertViewLabel showshowPopAlertViewWithMessage:error withLabelViewAlpha:0.8 setInsertWidth:20 insertHeiht:20 andFrameCenterYoffset:0.5];
}

- (void)isSimpleDrawingBoardr1Yc82LCJh50 {
    NSLog(@"Get User Succrss");
}

- (void)isSimpleDrawingBoardo91etxuR2JVl4jzdCFsA {
    NSLog(@"Continue");
}

- (void)isSimpleDrawingBoardmsJtcM0eT1L0pXNTBtWKVDFL {
    NSLog(@"Continue");
}

- (void)isSimpleDrawingBoardiTGcVx3UuKGXtnnd8X3K4 {
    NSLog(@"Continue");
}

- (void)isSimpleDrawingBoardEXeUSmTSR9bywD5uOJ1JU4 {
    NSLog(@"Get Info Failed");
}

- (void)isSimpleDrawingBoard2m5jk0I8GQFlmY {
    NSLog(@"Get Info Failed");
}

- (void)isSimpleDrawingBoardYcqFH087RJUbkWAXw {
    NSLog(@"Check your Network");
}

- (void)isSimpleDrawingBoardYFfQXo0n1AIGun {
    NSLog(@"Get Info Success");
}

- (void)isSimpleDrawingBoardiSNcAFpJXkYIVnRCfeY {
    NSLog(@"Continue");
}

- (void)isSimpleDrawingBoardUCHQAH0x71Tox2meFb5lOIHOv0 {
    NSLog(@"Check your Network");
}

- (void)isSimpleDrawingBoardQLSaFjK7WyoLYp {
    NSLog(@"Get Info Success");
}

- (void)isSimpleDrawingBoardBU9dx0jOMA4GTWCrH {
    NSLog(@"Check your Network");
}

- (void)isSimpleDrawingBoard4EhXVLQtLCYsIu {
    NSLog(@"Get User Succrss");
}

- (void)isSimpleDrawingBoardqhqJCsbmPryCu2vvDdbT {
    NSLog(@"Get Info Success");
}

- (void)isSimpleDrawingBoardBt3dNNzEkvtlw {
    NSLog(@"Continue");
}

- (void)isSimpleDrawingBoardLpR3YG5iz7jOnjirmKbm {
    NSLog(@"Get Info Failed");
}

- (void)isSimpleDrawingBoardmsLYUhdhCobmGIarKi6uQuJ {
    NSLog(@"Continue");
}

- (void)isSimpleDrawingBoard7ecfQMcjdikLrDArOL9B0u9ncu {
    NSLog(@"Get Info Success");
}

- (void)isSimpleDrawingBoardH39KANFsIDPwog8 {
    NSLog(@"Get Info Success");
}

- (void)isSimpleDrawingBoardBdfDyYm1J2EJ5o2 {
    NSLog(@"Get Info Failed");
}

- (void)isSimpleDrawingBoard5f5l1niiEF0RecJG {
    NSLog(@"Get Info Failed");
}

- (void)isSimpleDrawingBoardNher8D3YLblk5t82M0L {
    NSLog(@"Continue");
}

- (void)isSimpleDrawingBoardQcGO3KOViAfoivshN4A4a {
    NSLog(@"Check your Network");
}

- (void)isSimpleDrawingBoardTY2YcT6gmGTDARQ21wYkq219x {
    NSLog(@"Get User Succrss");
}
@end
